<?php
//！！重要说明：外部调用此模板必须是主查询
defined( 'ABSPATH' ) || exit;

$paged = $paged>0 ? $paged:1; 
//$query_obj=get_queried_object();//获取当前查询对象用get_the_category()也类似
//$max_paged=ceil($query_obj->category_count/$posts_per_page);//获取页码数$posts_per_page是一个全家变量（每页显示的文章数）

$max_paged=$wp_query->max_num_pages;

?>
<div class="blog-pagination">
	<ul>
		<li><a <?php if($paged>1){echo 'href="'.get_category_link($cat).($paged>2 ? '/page/'.($paged-1).'"':'"');}else{echo 'style="pointer-events:none"';}?>>上一页</a></li>
		
			
		<?php if($max_paged==$paged&&$max_paged>4){
			echo '<li><a href="'.get_category_link($cat).($paged==5 ? '">1':'/page/'.($paged-4).'">'.($paged-4)).'</a></li>
			<li><a href="'.get_category_link($cat).'/page/'.($paged-3).'">'.($paged-3).'</a></li>';
		}elseif($paged+1 == $max_paged&&$max_paged>3){
			echo'<li><a href="'.get_category_link($cat).($paged==4 ? '">1':'/page/'.($paged-3).'">'.($paged-3)).'</a></li>';
		}
		?>
		<li><a <?php if($paged==1){echo 'class="hers-on "';} ?> href="<?php echo get_category_link($cat).($paged>3 ? '/page/'.($paged-2).'">'.($paged-2):'">1');?></a></li>
		<li><a <?php if($max_paged<2){echo 'class="hers-hide"';}elseif($paged==2){echo 'class="hers-on "';} ?> href="<?php echo get_category_link($cat).($paged>3 ? '/page/'.($paged-1).'">'.($paged-1):'/page/2">2');?></a></li>
		<li><a <?php if($max_paged<3){echo 'class="hers-hide"';}elseif($paged>2){echo 'class="hers-on "';} ?> href="<?php echo get_category_link($cat).($paged>3 ? '/page/'.$paged.'">'.$paged:'/page/3">3');?></a></li>
		<?php 
		if($paged<4&&$max_paged>=4){
			echo '<li><a href="'.get_category_link($cat).'/page/4">4</a></li>';
		}elseif($paged>2&&$max_paged>=$paged+1){
			echo '<li><a href="'.get_category_link($cat).'/page/'.($paged+1).'">'.($paged+1).'</a></li>';
		}
		
		if($paged<4&&$max_paged>=5){
			echo '<li><a href="'.get_category_link($cat).'/page/5">5</a></li>';
		}elseif($paged>2&&$max_paged>=$paged+2){
			echo '<li><a href="'.get_category_link($cat).'/page/'.($paged+2).'">'.($paged+2).'</a></li>';
		}
		?>
		<li><a <?php if($max_paged==$paged){echo 'style="pointer-events:none"';}else{echo ' href="'.get_category_link($cat).'/page/'.($paged+1).'"';}?>>下一页</a></li>
	</ul>
</div>